﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OJobListEasyUI : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "OJobList";
            }
        }


        #region 属性 (查询条件)


        protected string CommonFiled
        {
            get
            {
                return GetRequestValue<string>("CommonFiled", "");

            }
        }
        protected string CommonValue
        {
            get
            {
                return GetRequestValue<string>("CommonValue", "");

            }
        }

        protected string MachineType
        {
            get
            {
                return GetRequestValue<string>("MachineType", "");
            }
        }
        protected string OnlineDateFrom
        {
            get
            {
                return GetRequestValue<string>("OnlineDateFrom", "");

            }
        }
        protected string OnlineDateTo
        {
            get
            {
                return GetRequestValue<string>("OnlineDateTo", "");

            }
        }

        protected string beforeInStorageDate
        {
            get
            {
                return GetRequestValue<string>("beforeInStorageDate", "");
            }
        }

        protected string Remark
        {
            get
            {
                return GetRequestValue<string>("Remark", "");
            }
        }

        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "JobId" : base.orderField;
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "DESC" : base.orderDirection;
            }
        }


        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection);
            }
        }

        #endregion

      

        protected string GetWhereSql()
        {
            string wheresql = QueryOperatorsEnumHelper.ConvertCommonOperator(CommonFiled, QueryOperatorsEnum.包含, CommonValue);
            string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("OnlineDate", QueryOperatorsEnum.范围, OnlineDateFrom + "|" + OnlineDateTo);

            if (!string.IsNullOrEmpty(wheresql) && !string.IsNullOrEmpty(DOWNSQL))
            {
                wheresql += " and " + DOWNSQL;
            }
            else if (!string.IsNullOrEmpty(DOWNSQL))
            {
                wheresql = DOWNSQL;
            }


            if (!MachineType.IsEmptyOrNull())
            {
                if (string.IsNullOrEmpty(wheresql))
                    wheresql = " MachineType='" + MachineType + "'";
                else
                    wheresql += " and MachineType='" + MachineType + "'";
            }

            if (!beforeInStorageDate.IsEmptyOrNull())
            {
                if (string.IsNullOrEmpty(wheresql))
                    wheresql = " OnlineDate>='" + beforeInStorageDate + "'";
                else
                    wheresql += " and OnlineDate>='" + beforeInStorageDate + "'";
            }


            if (!Remark.IsEmptyOrNull())
            {
                if (string.IsNullOrEmpty(wheresql))
                    wheresql = " Remark like '%" + Remark + "%'";
                else
                    wheresql += " and Remark like '%" + Remark + "%'";
            }

            return wheresql;
        }

        protected override string query()
        {
            DataTableCollection dts = null;
            dts = OJobController.GetPagination(GetWhereSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
            return ToDataGridJson(dts[0], TotalCount, dts[1]).ToString();

        }

        protected override string query2()
        {
            string sqlwhere = " IsSellStorage=1 ";
            DataTableCollection dts = null;
            dts = OJobController.GetPagination(sqlwhere, pageNum, numPerPage, SQLSort, ref TotalCount);
            return ToDataGridJson(dts[0], TotalCount, dts[1]).ToString();
        }
        protected override string query3()
        {
            string sqlwhere = " DATEDIFF(YEAR,InStorageDate,GETDATE())>=2 AND MACStock=1 ";
            DataTableCollection dts = null;
            dts = OJobController.GetPagination(sqlwhere, pageNum, numPerPage, SQLSort, ref TotalCount);
            return ToDataGridJson(dts[0], TotalCount, dts[1]).ToString();
        }

    }
}